<%@ page language="java" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>
    <%@include file="../common/base.jsp"%>
	<meta charset="utf-8" />
	<meta name ="viewport" content ="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
	<meta http-equiv="expires" content="0">
	<title>行程中</title>
    <link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${base}/css/global.css?version=${version}">
    <link rel="stylesheet" type="text/css" href="${base}/css/takecar.css?version=${version}">
</head>
<body>
    <div class="container-fluid">
    	<div class="divBox driver-info">
			<%@include file="driverHtml.jsp"%>
			<p class="tip" id="tip">行程中</p>
    	</div>
		<%@include file="startEnd.jsp"%>
    	<div class="divBox costBox row" id="isTaxi">
    		<div class="col-xs-3">
    			<span style="font-size: 18px;" id="totalFare"></span>
    		</div>
			<%--//TODO 这边需要根据后台返回的司机坐标，然后调用高德地图预算和终点的距离，还有时间并显示在界面上--%>
    		<div class="col-xs-9" style="padding: 0;text-align: center;">
    			<span style="color:#999;font-size: 12px;" id="timeLu"></span>
    			<span style="color: #3e88f5;"></span>
    		</div>
    	</div>
		<div class="l-footer">
			<%@include file="footer.jsp"%>
		</div>
    	<%--<a class="cancelBox">--%>
    		<%--<img src="/images/cancel.png">--%>
    		<%--<p class="text">取消订单</p>--%>
    	<%--</a>--%>
    </div>
</body>
<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/js/localStorageOpt.js?version=${version}"></script>
<script type="text/javascript" src="${base}/plugin/layer-v3.0.3/layer.js"></script>
<%--<script type="text/javascript" src="${base}/plugin/crypto-js/crypto-js.min.js"></script>--%>
<%--<script type="text/javascript" src="${base}/plugin/jsencrypt/jsencrypt.min.js"></script>--%>
<script type="text/javascript" src="${base}/js/utils.js?version=${version}"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
    var yun=new yueajax( "${openId}");
    //初始化请求订单数据
    if(getLocalStorage('isTaxi')=='true'){
        $('#isTaxi').hide();
    }

    getOrderStatus(function (data) {
        //订单创建时间
        var cTime=new Date(data.data.createOn);
        var cTobj=yun.time_count(cTime)
        var driver=data.data.driver;
        $('#faceimg').attr('src',driver.face || '${base}/images/man.png');
        $('#driver_name').html(driver.name);
        $('#driver_score').append(driver.score)
        $('#driver_orderCount').html(driver.orderCount+'单')
        $('#driver_plateNum').html(driver.plateNum)
        $('#driver_carColor_brandName').html(driver.carColor+driver.brandName);
        $('#driver_mobile').attr('href','tel:'+driver.mobile);
        $('#clickCall').attr('href','tel:'+driver.mobile);

        $('#creadtime').html(cTobj.day+'  '+cTobj.hour+cTime.format('hh:mm'));
        $("#originDetailAddressText").html(data.data.originAddress);
        $("#destDetailAddressText").html(data.data.destAddress);
    });
	//定时请求OrderDetail，获取订单详情
    var interval = setInterval(getOrderStatus,5000);
	//获取刚才派出的订单ID
	var isCommon=true;
	function getOrderStatus(callback) {
        yun.order_ajax(function(data){
            var d=data.data;
            changeUrl(data.data.subStatus,yun.orderUuid);
			if(isCommon){
                getCommon(data.data.typeTrip)
			}
            //请求司机等待时间和等待费用
            if(typeof callback =="function"){
                callback(data);
            }

//            订单状态是400：司机已到达目的地。
            if(d.subStatus==400){
                $('#tip').html('已到达目的地，请确认费用。');
                $('#timeLu').html('已到达目的地');
//                return;
			}
            if(d.subStatus==300){
                //订单状态是300：司机已到达目的地。
                $('#tip').html('行程中');
			}

            //乘客和司机距离，时间，路程计算亲求
            yun.twoPoint_ajax({
                drivingType:'endDriving'
            },function(data){
                var dd=data.data;
                var lu=(Math.round(dd.drivingJson.distance/100))/10,duration=Math.round(dd.drivingJson.duration/60);
                if(d.subStatus!=400){
                    if(lu<=0.1){
                        $('#timeLu').html('即将到达目的地，请携带好随身物品');
                    }else{
                        $('#timeLu').html('距离目的地'+lu+'公里，预计行驶'+duration+'分钟。');
                    }
				}
				var realFare=dd.realTimeFare
                $('#totalFare').html((realFare?realFare.totalFare:0)+"元");
            },function(data){
                $('#timeLu').html(data.msg);
                clearInterval(interval)
            })
        },function (data) {
            clearInterval(interval)
//            layer.msg(data.msg());clearInterval(interval);
        })
	}

	function getCommon (businessType){
        // yun.ajax_md5(
        //     {
        //         identify:1,
        //         businessType:businessType
        //     },
        //     '/api/v1/common/getCommoncfg',
        //     function(result){
        //         isCommon=false;
        //         for(var i in result.data){
        //             var d = result.data[i];
        //             if(d.businessType==businessType && d.configKey=='REAL_TIME_CHARGING' && d.configValue==0){
        //                 $('#isTaxi').find('.col-xs-3').remove()
        //                 $('#isTaxi').find('.col-xs-9').attr('class','col-xs-12')
		// 			}
		// 		}
		//
        //     }
        // )
	}

});
</script>
</html>